package com.mininglamp.main;

import com.mininglamp.drools.RuleEngineApp;
import com.mininglamp.mode.Input;
import com.mininglamp.mode.Output;
import org.drools.core.common.ProjectClassLoader;
import org.drools.core.io.impl.ResourceFactoryServiceImpl;
import org.kie.internal.io.ResourceFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * @author xiewendong@mininglamp.com
 * @Description:
 * @since 2017/8/11 13:34
 */
public class Main {

   // private static org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(Main.class);

    protected static final Logger logger          = LoggerFactory.getLogger( Main.class );

    public static void main(String[] args){

       // log.info("log4j.....");

        logger.info("Main is Started....");
        /*触发规则一*/
        /*Input input=new Input("谢文东","男","18","湖南",1.8D,1000000);
        Output output = RuleEngineApp.execute(input);
        System.out.println(output.getDesc());*/

        /*触发规则二*/
        /*Input input=new Input("王柳","女","18","湖南",1.8D,1000000);
        Output output = RuleEngineApp.execute(input);
        System.out.println(output.getDesc());*/


//        findParentClassLoader();

         /*触发规则三*/
        Input input=new Input("刘磊","男","18","湖南",1.69D,1500);
        while (true){
            Output output = RuleEngineApp.execute(input);
            System.out.println(output.getDesc());

            try {
                Thread.sleep(1000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            break;
        }



//        ResourceFactoryServiceImpl

//        ResourceChangeScannerConfiguration sconf = ResourceFactory
//                .getResourceChangeScannerService()
//                .newResourceChangeScannerConfiguration();
//
//        ResourceFactory.getResourceChangeScannerService().configure(sconf);
//        ResourceFactory.getResourceChangeNotifierService().start();
//        KnowledgeAgentConfiguration aconf = KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
//
//        KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent("",aconf);
//        kagent.applyChangeSet(ResourceFactory.newClassPathResource("resource.xml"));
//
//
//        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
//        kbuilder.add( ResourceFactory.newClassPathResource( "htp://www.domain.org/myrules.drl", this.getClass()),
//                               ResourceType.DRL );

    }


    public static ClassLoader findParentClassLoader() {
        ClassLoader parent = Thread.currentThread().getContextClassLoader();
        if (parent == null) {
            parent = ClassLoader.getSystemClassLoader();
        }
        if (parent == null) {
            parent = ProjectClassLoader.class.getClassLoader();
        }
        return parent;
    }
}
